<template>
  <div class="tab-pane fade" :id="id" role="tabpanel">
    <div class="card col-12">
      <div class="card-body">
        <form id="frmEtermConfig" class="form-horizontal">
          <div class="row">
            <label class="control-label col-2 ms-auto text-end"
              >全局国内机票加价</label
            >
            <div class="col-4 me-auto">
              <input
                type="input"
                class="form-control"
                v-model.number="domFlightMarkup"
              />
            </div>
          </div>
          <div class="row">
            <label class="control-label col-2 ms-auto text-end"
              >全局国际机票加价</label
            >
            <div class="col-4 me-auto">
              <input
                type="input"
                class="form-control"
                v-model.number="intlFlightMarkup"
              />
            </div>
          </div>
          <div class="row">
            <label class="control-label col-2 ms-auto text-end"
              >全局酒店加价</label
            >
            <div class="col-4 me-auto">
              <input
                type="input"
                class="form-control"
                v-model.number="hotelMarkup"
              />
            </div>
          </div>
          <div class="row">
            <label class="control-label col-2 ms-auto text-end"
              >全局用车加价</label
            >
            <div class="col-4 me-auto">
              <input
                type="input"
                class="form-control"
                v-model.number="carMarkup"
              />
            </div>
          </div>
          <div class="row">
            <label class="control-label col-2 ms-auto text-end"
              >全局登机牌办理加价</label
            >
            <div class="col-4 me-auto">
              <input
                type="input"
                class="form-control"
                v-model.number="cardMarkup"
              />
            </div>
          </div>

          <div class="row">
            <button
              id="btnChange"
              type="button"
              class="btn btn-primary  col-4 offset-4"
              :disabled="saving"
              @click.stop="saveGlobalPriceConfig()"
            >
              保存
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script>
import { searchGlobalPriceConfig, saveGlobalPriceConfig } from "@/api/admin.js";

export default {
  props: {
    id: {
      type: String,
    },
  },
  data() {
    return {
      hotelMarkup: 0,
      carMarkup: 0,
      cardMarkup: 0,
      domFlightMarkup: 0,
      intlFlightMarkup: 0,

      saving: false,
    };
  },
  mounted: function () {
    this.searchGlobalPriceConfig();
  },
  methods: {
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    searchGlobalPriceConfig: function () {
      searchGlobalPriceConfig((v) => {
        this.hotelMarkup = v.hotelMarkup;
        this.carMarkup = v.carMarkup;
        this.cardMarkup = v.boardingCardMarkup;
        this.domFlightMarkup = v.domFlightMarkup;
        this.intlFlightMarkup = v.intlFlightMarkup;
      });
    },
    saveGlobalPriceConfig: function () {
      const params = {
        hotelMarkup: this.hotelMarkup,
        carMarkup: this.carMarkup,
        boardingCardMarkup: this.cardMarkup,
        domFlightMarkup: this.domFlightMarkup,
        intlFlightMarkup: this.intlFlightMarkup,
      };

      this.saving = true;

      saveGlobalPriceConfig(
        params,
        (v) => {
          if (v.status === "OK") this.showErrMsg("保存成功");
          else this.showErrMsg(v.errmsg, "danger");
        },
        () => {
          this.saving = false;
        }
      );
    },
  },
};
</script>